package com.csun.cmny.provider.controller.wechat;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.dto.wechat.BindMobileDto;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.WeiXinService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2021-01-19 13:41
 * @Description:
 */
@RestController
@RequestMapping(value = "/wx", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class WeiXinController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;
    @Resource
    private WeiXinService weiXinService;

    /**
     * 绑定手机号
     *
     * @param bindMobileDto the bind mobile dto
     *
     * @return  the wrapper.
     */
    @PostMapping(value = "/bindMobile")
    public Wrapper bindMobile(BindMobileDto bindMobileDto) {

        Integer result = weiXinService.bindMobile(bindMobileDto, getLoginAuthDto());
        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null), result);
    }

}
